package com.GDOU.controller;

import com.GDOU.bean.Student;
import com.GDOU.service.StudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //添加学生
    @PostMapping("/add.do")
    public Integer addStudent(Student student){
        return studentService.addStudent(student);
    }

    //删除学生
    @GetMapping("/delete.do")
    public Integer deleteStudent(@RequestParam("stuNum") String stuNum){
        return studentService.deleteStudent(stuNum);
    }

    //修改学生
    @GetMapping("/update.do")
    public Integer updateStudent(Student student){
        return studentService.updateStudent(student);
    }

    //分页查询所有学生信息
    @GetMapping("/list.do")
    public PageInfo<Student> getStudentPage(@RequestParam("pageNum") Integer pageNum){
        //获取学生的分页信息
        PageInfo<Student> page=studentService.getStudentPage(pageNum);
        //将分页数据返回
        return page;
    }

    //通过姓名获取学生信息
    @GetMapping("name.do")
    public Student getStudentByName(@RequestParam("stuName")String stuName){
        return studentService.getStudentByName(stuName);
    }
}
